home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Freelog 125
/
Freelog_MarsAvril2015_No125.iso
/
Musique
/
Quod Libet
/
quodlibet-3.3.0-installer.exe
/
bin
/
quodlibet
/
ext
/
events
/
rbimport.pyc
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2014-12-31
|
5KB
|
135 lines
# Source Generated with Decompyle++
# File: in.pyc (Python 2.7)
import xml.sax as xml
from xml.sax.handler import ContentHandler
from gi.repository import Gtk
from quodlibet import app
from quodlibet import util
from quodlibet.qltk.msg import WarningMessage, ErrorMessage
from quodlibet.util.uri import URI
from quodlibet.util.path import expanduser, normalize_path
from quodlibet.plugins.events import EventPlugin
class RBDBContentHandler(ContentHandler):
def __init__(self, library):
ContentHandler.__init__(self)
self._library = library
self._current = None
self._tag = None
self._changed_songs = []
def characters(self, content):
if self._current is not None and self._tag is not None:
self._current[self._tag] = content
def startElement(self, name, attrs):
self._tag = None
if name == 'entry' and attrs.get('type') == 'song':
self._current = { }
elif name in ('location', 'rating', 'play-count', 'last-played'):
self._tag = name
def endElement(self, name):
self._tag = None
if name == 'entry' and self._current is not None:
current = self._current
self._current = None
if len(current) > 1:
uri = current.pop('location', '')
try:
p_uri = URI(uri)
except ValueError:
return None
if not p_uri.is_filename:
return None
None._process_song(normalize_path(p_uri.filename), current)
def _process_song(self, path, stats):
song = self._library.get(path, None)
if not song:
return None
has_changed = None
if 'rating' in stats:
try:
value = int(stats['rating']) / 5
except ValueError:
pass
song['~#rating'] = value
has_changed = True
if 'play-count' in stats:
try:
value = int(stats['play-count'])
except ValueError:
pass
song['~#playcount'] = value
has_changed = True
if 'last-played' in stats:
try:
value = int(stats['last-played'])
except ValueError:
pass
if value > song('~#lastplayed', 0):
song['~#lastplayed'] = value
has_changed = True
if has_changed:
self._changed_songs.append(song)
def finish(self):
'''Call at the end, also returns amount of imported songs'''
count = len(self._changed_songs)
self._library.changed(self._changed_songs)
self._changed_songs = []
return count
def do_import(parent, library):
db_path = expanduser('~/.local/share/rhythmbox/rhythmdb.xml')
handler = RBDBContentHandler(library)
try:
xml.sax.parse(db_path, handler)
except Exception:
util.print_exc()
handler.finish()
msg = _('Import Failed')
ErrorMessage(parent, RBImport.PLUGIN_NAME, msg).run()
count = handler.finish()
msg = _('Successfully imported ratings and statistics for %d songs') % count
WarningMessage(parent, RBImport.PLUGIN_NAME, msg).run()
class RBImport(EventPlugin):
PLUGIN_ID = 'rbimport'
PLUGIN_NAME = _('Rhythmbox Import')
PLUGIN_DESC = _('Import ratings and song statistics from Rhythmbox')
def PluginPreferences(self, *args):
button = Gtk.Button(label = _('Start Import'))
def clicked_cb(button):
do_import(button, app.library)
button.connect('clicked', clicked_cb)
return button